﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for QuangCaoDAO
/// </summary>
public class QuangCaoDAO:AbstractDAO
{
	public QuangCaoDAO(String strPath)
        : base(strPath)
    {

    }
    ~QuangCaoDAO()
    {
        base.Dispose();
    }

    public DataSet SelectQuangCaoAll()
    {
        DataSet ds;
        try
        {
            ds = new DataSet();
            base.sql = "usp_SelectQuangCaoAll";
            base.FillDataSet(ref ds, "SelectQuangCaoAll");
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
        finally
        {
            base.CleanUpObject();
        }
    }

    public DataSet SelectQuangCao(int id)
    {
        DataSet ds;
        try
        {
            ds = new DataSet();
            base.sql = "usp_SelectQuangCao";
            base.InitializeCommand();

            base.AddParameter("@id",
            SqlDbType.Int, 10, id);

            base.FillDataSet(ref ds, "SelectQuangCao");
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
        finally
        {
            base.CleanUpObject();
        }
    }

    public DataSet SelectQuangCaoByViTri(int vitri)
    {
        DataSet ds;
        try
        {
            ds = new DataSet();
            base.sql = "usp_SelectQuangCaoByViTri";
            base.InitializeCommand();

            base.AddParameter("@ViTri",
            SqlDbType.Int, 10, vitri);

            base.FillDataSet(ref ds, "SelectQuangCaoByViTri");
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
        finally
        {
            base.CleanUpObject();
        }
    }

    public Boolean InsertQuangCao(QuangCaoDTO qc)
    {
        try
        {
            base.sql = "usp_InsertQuangCao";
            base.InitializeCommand();

            base.AddParameter("@NgayBatDau",
            SqlDbType.DateTime, 100, qc.NgayBatDau);

            base.AddParameter("@NgayKetThuc",
            SqlDbType.DateTime, 100, qc.NgayKetThuc);

            base.AddParameter("@ViTri",
            SqlDbType.Int, 100, qc.ViTri);

            base.AddParameter("@Gia",
            SqlDbType.BigInt, 100, qc.Gia);

            base.AddParameter("@TenKhachHang",
            SqlDbType.NVarChar, 100, qc.TenKhachHang);

            base.AddParameter("@HinhMinhHoa",
            SqlDbType.NVarChar, 200, qc.HinhMinhHoa);

            base.AddParameter("@WebSite",
            SqlDbType.NVarChar, 200, qc.WebSite);

            return ExecuteStoredProcedure();
        }
        catch (System.Exception ExceptionErr)
        {
            throw new Exception(ExceptionErr.Message, ExceptionErr.InnerException);

        }
    }

    public Boolean UpdateQuangCao(QuangCaoDTO qc, int type)
    {
        try
        {
            base.sql = "usp_UpdateQuangCao";
            base.InitializeCommand();

            base.AddParameter("@id",
            SqlDbType.Int, 10, qc.Id);

            base.AddParameter("@NgayBatDau",
            SqlDbType.DateTime, 100, qc.NgayBatDau);

            base.AddParameter("@NgayKetThuc",
            SqlDbType.DateTime, 100, qc.NgayKetThuc);

            base.AddParameter("@ViTri",
            SqlDbType.Int, 100, qc.ViTri);

            base.AddParameter("@Gia",
            SqlDbType.BigInt, 100, qc.Gia);

            base.AddParameter("@TenKhachHang",
            SqlDbType.NVarChar, 100, qc.TenKhachHang);

            base.AddParameter("@HinhMinhHoa",
            SqlDbType.NVarChar, 200, qc.HinhMinhHoa);

            base.AddParameter("@WebSite",
            SqlDbType.NVarChar, 200, qc.WebSite);

            base.AddParameter("@type",
            SqlDbType.Int, 10, type);

            return ExecuteStoredProcedure();
        }
        catch (System.Exception ExceptionErr)
        {
            throw new Exception(ExceptionErr.Message, ExceptionErr.InnerException);

        }
    }

    public Boolean DeleteQuangCao(int id)
    {
        try
        {
            base.sql = "usp_DeleteQuangCao";
            base.InitializeCommand();

            base.AddParameter("@id",
            SqlDbType.Int, 10, id);

            return ExecuteStoredProcedure();
        }
        catch (System.Exception ExceptionErr)
        {
            throw new System.Exception(ExceptionErr.Message,
            ExceptionErr.InnerException);
        }
    }
}
